//
// Created by PC on 2022/12/27.
// 完美立方 a^3 = b^3+c^3+d^3 对于给定的N, 使1>a,b,c,d>=N,且b<=c<=d
// MOOC 程序设计与算法(二) 例题1
//

#include <iostream>

using namespace std;

bool equal(int left, int right)
{
    if (left * left * left == right)
        return true;
    return false;
}

void cube(int n)
{
//    int b = 6 * 6 * 6 + 8 * 8 * 8 + 10 * 10 * 10;

    int r = 0;
    int count = 0;
    for (int a = 2; a <= n; ++a)
    {
        for (int b = 2; b < a; ++b)
        {
            for (int c = b; c < a; ++c)
            {
                for (int d = c; d < a; ++d)
                {
                    r = b * b * b + c * c * c + d * d * d;
                    if (equal(a, r))
                        printf("%d: Cube=%d, Triple(%d,%d,%d)\n", ++count,a, b, c, d);
                }
            }

        }

    }
}

int main()
{
    int num = 24;
    cube(num);
    return 0;
}
